//
//  DBHelper.m
//  ChinaBrowser
//
//  Created by David on 14/11/24.
//  Copyright (c) 2014年 KOTO Inc. All rights reserved.
//

#import "DBHelper.h"

//#import "ModelUrl.h"
//
//#import "ADOFavorite.h"
//#import "ADOHistory.h"

/*
 
 "CREATE TABLE tab_favorite ("
 "fid INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT DEFAULT 1,"
 "fid_server INTEGER DEFAULT 0,"
 "uid INTEGER DEFAULT 0,"
 "title TEXT,"
 "link TEXT,"
 "time Double DEFAULT 0,"
 "data_type INTEGER DEFAULT 0)";
 
 */
NSString * const DB_NAME1 = @"jishi_dpt.db";
NSString * const DB_NAME2 = @"youtao.sqlite";

static DBHelper *dbhelper;

@interface DBHelper ()

//@property (nonatomic, strong) FMDatabase *db;
//
//@end
//
//@implementation DBHelper
//
//- (void)setup
//{
//    
//    _db = [[FMDatabase alloc] initWithPath:GetDBPathWithName(DB_NAME2)];
//    [_db open];
//    
//    [self createTable];
//}
//
///**
// *  DoomeBrowserX_1.sqlite => doome_x.sqlite
// *
// *  @return 是否需要更新
// */
//- (BOOL)updateIfNeeded1
//{
//    BOOL flag = NO;
//    NSString *dbpath = GetDBPathWithName(DB_NAME1);
//    flag = [[NSFileManager defaultManager] fileExistsAtPath:dbpath];
//    if (flag) {
//        FMDatabase *db = [[FMDatabase alloc] initWithPath:dbpath];
//        [db open];
//        
//        // 网址表
//        {
//            FMResultSet *set = [db executeQuery:@"select * from tab_favorite"];
//            while ([set next]) {
//                NSDictionary *dictResult = [set resultDictionary];
//                ModelUrl *model = [ModelUrl modelWithResultSetDict:dictResult];
//                NSInteger type = [dictResult[@"data_type"] integerValue];
//                if (2==type) {
//                    // 收藏
//                    model.pkid = [ADOFavorite addModel:model];
//                }
//                else if (3==type) {
//                    // 历史记录
//                    model.pkid = [ADOHistory addModel:model];
//                }
//            }
//        }
//        
//        
//        [[NSFileManager defaultManager] removeItemAtPath:dbpath error:nil];
//    }
//    return flag;
//}
//
//- (void)createTable
//{
//    NSString *sql_fav = @"CREATE TABLE IF NOT EXISTS tab_fav ("
//    "pkid integer not null primary key autoincrement default 1,"
//    "title text,"
//    "shopLink text,"
//    "videoLink text,"
//    "link text,"
//    "time double)";
//    
//    NSString *sql_history = @"CREATE TABLE IF NOT EXISTS tab_history ("
//    "pkid integer not null primary key autoincrement default 1,"
//    "title text,"
//    "shopLink text,"
//    "videoLink text,"
//    "link text,"
//    "time double)";
//    
//    NSArray *arrSql = @[sql_fav,
//                        sql_history];
//    for (NSString *sql in arrSql) {
//        [_db executeUpdate:sql];
//    }
//}
//
//- (instancetype)init
//{
//    self = [super init];
//    if (self) {
//        [self setup];
//    }
//    return self;
//}
//
//+ (instancetype)shareDBHelper
//{
//    static dispatch_once_t onceToken;
//    dispatch_once(&onceToken, ^{
//        dbhelper = [[DBHelper alloc] init];
//    });
//    return dbhelper;
//}
//
//+ (FMDatabase *)db
//{
//    return [DBHelper shareDBHelper].db;
//}
//
//- (BOOL)updateIfNeeded
//{
//    return [self updateIfNeeded1];
//}

@end
